-
Notifications
You must be signed in to change notification settings - Fork 899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix Docker integration docs for intermediate layers #7166
base: main
Are you sure you want to change the base?
Conversation
I would also suggest that we add
Uv detects that the cache sits on a different filesystem (yay!), but it's probably a good idea to make this explicit in the Dockerfile. It's also mandatory to use this option, even if you don't use a cache mount, if you plan on copying only your project directory from another stage (e.g. when combining multiple stages), you likely won't think about copying (and merging!) the UV cache directory. Admittedly, that is a bit of an edge case. Adding edit: I've made these changes in ea61ed1, let me know what you think. |
--mount=type=bind,source=uv.lock,target=uv.lock \ | ||
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't these be added by the ADD . /app
invocation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh my, I blame tunnel vision. 🤦
In my case I added only the src
directory because ADD . /app
adds a lot of things that I don't want to add. Thinking about it, with --link-mode=copy
, I could probably even --mount
the source directory itself as well? Arguably, a very minor optimization as you don't usually have many hundreds of megabytes of source code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The source directory needs to stick around because we don't support non-editable installs of workspace members during syncs yet (#5792). Maybe it'd be best to address your case in the documentation by adding a case to the optimization examples for copying the src directory instead of the full project directory?
@@ -340,18 +340,31 @@ WORKDIR /app | |||
RUN --mount=type=cache,target=/root/.cache/uv \ | |||
--mount=type=bind,source=uv.lock,target=uv.lock \ | |||
--mount=type=bind,source=pyproject.toml,target=pyproject.toml \ | |||
uv sync --frozen --no-install-project | |||
uv sync --frozen --no-install-project --link-mode=copy --compile-bytecode |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I have a preference for setting an environment variable for this as in astral-sh/uv-docker-example#16
I think we cover bytecode compilation in a separate example though https://docs.astral.sh/uv/guides/integration/docker/#compiling-bytecode
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree that bytecode compilation shouldn't be included in this example, as it is already covered afterwards
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fair point, although I feel obliged to point out that it also talks about caching later but uses a cache mount in this example already. :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I missed that when someone added the bind mounts to the example in #6921 — we should probably drop that from here too for clarity.
Thanks for contributing! I have a couple questions :) |
Summary
The Docker integration docs were missing to mount the
uv.lock
andpyproject.toml
which are required also for the second layer that runsuv sync --locked
.It also failed to mention that if your
pyproject.toml
references a readme file, that it must be mounted as well.